#ifndef _DIR_H
#define _DIR_H

#ifdef _WIN32
#include <windows.h>
#include <winbase.h>
#else
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#endif

/**
This class allows for easy retreival of files given a pattern.
*/
class DirectoryListing {
#ifdef _WIN32
	HANDLE h1;
public:
	DirectoryListing() { h1 = NULL; }
	~DirectoryListing() { if(h1) FindClose(h1); }
#else
	DIR *dp;
	dirent *ep;
	char *pattern;
public:
	DirectoryListing() { dp = NULL; ep = NULL; pattern = NULL; }
	~DirectoryListing() { if(dp) closedir(dp); if(pattern) delete[] pattern; }
#endif

public:
	/** Starts the search query. 

	On both windows and linux you can search for things such as "*.fwv". 
	The pattern style is "windowish", meaning that we can be consistend across platform. bash style 
	patterns are NOT supported.
	
	@param result the first file found
	@param type the search pattern
	*/

	void First(char *result,const char *type);

/**
	Retrieves the next file. 
	@see First
*/
	bool Next(char *result);
};

/** Miscelaneous directory functions */
class DirUtil {
public:
	static bool CreateDir(const char *name);
	static void RemoveExtension(char *out,char *str);
};

#endif


